const express = require('express'); // 引入express
const cors = require('cors'); // 引入cors
const app = express();
const Usrlogic = require('../../logic/userLogic');

// 使用cors解决跨域问题
app.use(cors());

// 使用express.json()中间件解析json格式的请求体
app.use(express.json());

app.get('/', (req,res) => Usrlogic.test(req,res));

// 获取版本号
app.get('/version', (req, res) => Usrlogic.getVersion(req, res));

// 数据库
app.get('/user', (req, res) => Usrlogic.getDB(req, res));

// 登录
app.get('/loginGame', (req, res) => Usrlogic.login(req, res));

// 注册用户
app.get('/register', (req, res) => Usrlogic.register(req, res));

// 创建角色
app.post('/createRole', (req, res) => Usrlogic.createRole(req, res));

// 获取建筑物信息
app.get('/getBuildInfo', (req, res) => Usrlogic.getBuildingInfo(req, res));

exports.start = (config) => {
    app.listen(config.CLIENT_PORT, () => {
        console.log(`User server is running on port ${config.CLIENT_PORT}`);
    })
}